package cn.wp.quartz.service.impl;

import cn.wp.quartz.domain.QuartzInfo;
import cn.wp.quartz.service.IQuartzInfoService;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

@Service
public class QuartzInfoServiceImpl implements IQuartzInfoService {

    @Autowired
    private SchedulerFactoryBean factoryBean;

    @Override
    public void addJob(QuartzInfo quartzInfo) {
        Scheduler scheduler = factoryBean.getScheduler();
        cn.itsource.quartz.utils.QuartzUtils.addJob(scheduler, quartzInfo.getJobName(),quartzInfo.getCls()
                ,quartzInfo.getParams() ,quartzInfo.getCron() );
    }

    @Override
    public void removeJob(String jobName) {
        Scheduler scheduler = factoryBean.getScheduler();
        cn.itsource.quartz.utils.QuartzUtils.removeJob(scheduler, jobName);
    }
}
